package com.yisoo.ubag.iot.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yisoo.ubag.iot.entity.TopicEntity;
import com.yisoo.ubag.iot.service.TopicService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-02-12 01:31:05
 */
@RestController
@RequestMapping("iot/topic")
public class TopicController {
    @Autowired
    private TopicService topicService;


    @RequestMapping("/test")
    public R test(){
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("iot:topic:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = topicService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tempId}")
    //@RequiresPermissions("iot:topic:info")
    public R info(@PathVariable("tempId") Long tempId){
		TopicEntity topic = topicService.getById(tempId);

        return R.ok().put("topic", topic);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("iot:topic:save")
    public R save(@RequestBody TopicEntity topic){
		topicService.save(topic);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("iot:topic:update")
    public R update(@RequestBody TopicEntity topic){
		topicService.updateById(topic);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("iot:topic:delete")
    public R delete(@RequestBody Long[] tempIds){
		topicService.removeByIds(Arrays.asList(tempIds));

        return R.ok();
    }

}
